Skip to content

Durga dom manipulation js#538

Open
Saidurgasatturi wants to merge 2 commits intoaptyInc:mainfrom
Saidurgasatturi:durga-dom-manipulation-js
Open

Durga dom manipulation js#538
Saidurgasatturi wants to merge 2 commits intoaptyInc:mainfrom
Saidurgasatturi:durga-dom-manipulation-js

Conversation

@Saidurgasatturi
Copy link
Copy Markdown

@Saidurgasatturi Saidurgasatturi commented Nov 4, 2025

Terms and Conditions

  • I Accept losing points if my PR does not follow the best practices mentioned below, which will impact my overall performance in training

HTML Best Practices

  • File Naming Convention:

  • Follow consistent and descriptive naming (e.g., dashboard.html, user-profile.html).

  • Use lowercase letters and hyphens instead of spaces.

  • Page Title:

  • Ensure the <title> tag is descriptive and aligns with the page content.

  • Include meaningful keywords for SEO if applicable.

  • Semantic Markup:

  • Use appropriate tags like <header>, <footer>, <section>, <article> for better readability and accessibility.

  • Accessibility Standards:

  • Ensure the use of alt attributes for images and proper labels for form elements.

  • Use ARIA roles where necessary.

  • Validation:

  • Ensure the code passes HTML validation tools without errors or warnings.

  • Structure and Indentation:

  • Maintain consistent indentation and proper nesting of tags.

  • Attributes:

  • Ensure all required attributes (e.g., src, href, type, etc.) are correctly used and not left empty.

CSS Best Practices

  • File Organization:

  • Use modular CSS files if applicable (e.g., base.css, layout.css, theme.css).

  • Avoid inline styles unless absolutely necessary.

  • Naming Conventions:

  • Use meaningful class names following BEM or other conventions (e.g., block__element--modifier).

  • Code Reusability:

  • Avoid duplicate code; use classes or mixins for shared styles.

  • Responsive Design:

  • Ensure proper usage of media queries for mobile, tablet, and desktop views.

  • Performance Optimization:

  • Minimize the use of unnecessary CSS selectors.

  • Avoid overly specific selectors and ensure selectors are not overly deep (e.g., avoid #id .class1 .class2 p).

  • Consistency:

  • Follow consistent spacing, indentation, and use of units (rem/em vs. px).

  • Maintain a single coding style (e.g., always use double or single quotes consistently).

Javascript Best Practices

  • File Organization:

  • Ensure scripts are modular and logically separated into files if needed.

  • Avoid mixing inline JavaScript with HTML.

  • Logic Optimization:

  • Check for redundancy and ensure the code is optimized for performance.

  • Avoid unnecessary API calls or DOM manipulations.

  • Solution Approach:

  • Confirm that the code solves the given problem efficiently.

  • Consider scalability for future enhancements.

  • Readability:

  • Use clear variable and function names.

  • Add comments for complex logic or algorithms.

  • Error Handling:

  • Ensure proper error handling for API calls or user input validation.

  • Code Quality:

  • Check for potential bugs (e.g., missing await, mishandling of null/undefined values).

  • Avoid unnecessary console.log statements in production code.

  • Security:

  • Avoid hardcoding sensitive data.

  • Sanitize user input to prevent XSS and other vulnerabilities.

  • Best Practices:

  • Use const and let instead of var.

  • Follow ES6+ standards where applicable.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @Saidurgasatturi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the codebase by adding multiple assignments that delve into core web development concepts, specifically DOM manipulation with JavaScript and fundamental CSS styling. The changes provide practical, hands-on examples for interacting with the browser's Document Object Model, including complex scenarios like iframe and Shadow DOM manipulation, to enhance understanding and skill development in dynamic web interfaces.

Highlights

  • New DOM Manipulation Assignments: Introduced a series of JavaScript assignments focused on various DOM manipulation techniques, covering element access, modification, and dynamic content management.
  • Iframe and Shadow DOM Interaction: Added examples demonstrating how to access and manipulate elements within iframes and Shadow DOMs, showcasing advanced DOM interaction scenarios.
  • Dynamic UI Features: Implemented functionalities such as counting elements, updating list items, toggling div visibility, and reordering table rows dynamically using JavaScript.
  • CSS Styling and Responsiveness: Included basic CSS styling for all new assignments, along with an example demonstrating CSS animations and media queries for responsive design.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds several assignments related to CSS and JavaScript DOM manipulation. While the code demonstrates a foundational understanding of the topics, there are several significant areas for improvement regarding best practices, correctness, and maintainability. Key issues include the use of inline event handlers which mix JavaScript with HTML, the use of document.write() which is a deprecated and unsafe practice, and logical flaws in some assignments such as hardcoded element selection instead of dynamic interaction. Additionally, there are opportunities to improve CSS by avoiding inline styles and managing colors more effectively with variables. I've provided specific comments with code suggestions to address these points. Implementing these changes will greatly enhance the quality and robustness of the code.

}

document.getElementById("upBtn").addEventListener("click", () => {
const selectedRow = tbody.querySelector("tr:nth-child(3)"); // example: move 3rd row
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The logic for moving rows is critically flawed. It hardcodes the selection to always be the third row (tr:nth-child(3)). This does not meet the assignment's requirement to replicate the functionality of Assignment 8, where any row could be moved. You need to implement a dynamic way to select a row to be moved, for example by clicking on it, and then use the external buttons to move the selected row.

Comment on lines +43 to +45
iframeDoc.open();
iframeDoc.write(innerHTMLContent);
iframeDoc.close();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using document.write() is strongly discouraged as it has performance issues and can be unsafe. A better approach for populating an iframe is to use the srcdoc attribute. This also simplifies the logic for attaching event listeners, which should be done in the iframe's onload event.

  const iframe = document.getElementById("myFrame");
  iframe.srcdoc = innerHTMLContent;
  iframe.onload = () => {
    const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;

<td>
<p id="para1">Paragraph 1</p>
<p id="para2">Paragraph 2</p>
<button onclick="changeColorById()">Change Color</button>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using onclick attributes directly in the HTML mixes JavaScript logic with your markup. This violates the principle of separation of concerns and makes the code harder to maintain. It's a best practice to attach event listeners from your JavaScript file using addEventListener. You should apply this to all buttons.

Suggested change
<button onclick="changeColorById()">Change Color</button>
<button id="changeColorBtn">Change Color</button>

Comment on lines +43 to +45
iframeDoc.open();
iframeDoc.write(iframeHTML);
iframeDoc.close();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of document.write() is a deprecated and unsafe practice that should be avoided. It can cause performance problems and security vulnerabilities. To populate the iframe, consider using the srcdoc attribute or creating a Blob with the HTML content and setting the iframe's src to a URL created from it.

iframe.srcdoc = iframeHTML;
iframe.onload = () => {
  const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;

let output = "";
ids.forEach(id => {
const el = document.getElementById(id);
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The random color generation logic can produce invalid hex color codes. toString(16) will not pad with leading zeros, so for smaller numbers, you might get a string shorter than 6 characters (e.g., #fff). This will result in an incorrect color. You should ensure the hex string is always 6 characters long.

Suggested change
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16);
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');

let output = "<ul>";

for (let elem of topLevelElements) {
if (elem.id === "countBtn" || elem.id === "result") continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to exclude the button and result div from the count by checking their IDs is brittle. If the IDs change, the code will break. A more robust approach would be to wrap the content you want to analyze in a container element and iterate over its children.

Comment on lines +7 to +16
row.innerHTML = `
<td>${i}</td>
<td>Item ${i}</td>
<td>
<button class="up">Up</button>
<button class="down">Down</button>
<button class="top">Top</button>
<button class="bottom">Bottom</button>
</td>
`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Creating DOM elements by building an HTML string with innerHTML is generally not recommended, especially when the elements are interactive. It's less safe (can lead to XSS if data is not properly sanitized) and can be less performant than using DOM APIs like document.createElement(). A better approach is to create elements programmatically and append them.

Comment on lines +7 to +19
<style>
iframe {
width: 100%;
height: 400px;
border: 2px solid black;
margin-top: 10px;
}

button {
margin: 5px;
padding: 5px 10px;
}
</style>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The CSS styles are defined inside a <style> tag in the HTML file. To follow best practices for separation of concerns and maintainability, these styles should be moved to an external CSS file and linked in the document's <head>.

<button onclick="toggleClassColor()">Toggle Background</button>
</td>
<td>
<span>Tag Span 1</span><br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using <br> tags to create vertical spacing between elements is not a good practice for layout. CSS should be used for styling and positioning. For example, you can make the <span> elements block-level or use flexbox/grid on their container to control their layout.

Suggested change
<span>Tag Span 1</span><br>
<span>Tag Span 1</span>

Comment on lines +7 to +55
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #f0f0f0;
}
.box {
width: 150px;
height: 150px;
background: #3498db;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
color: white;
font-weight: bold;
animation: bounce 2s infinite;
}
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-50px);
}
}
@media (max-width: 768px) {
.box {
width: 120px;
height: 120px;
font-size: 14px;
background: #e67e22;
}
}

@media (max-width: 480px) {
.box {
width: 90px;
height: 90px;
font-size: 12px;
background: #2ecc71;
}
}
</style>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The CSS styles are currently inside a <style> tag within the HTML file. According to the best practices mentioned in the pull request description, CSS should be in separate files to improve modularity and separation of concerns. Please move these styles to an external CSS file and link it in the <head>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant